package com.lc.luzhengtang.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.lc.luzhengtang.BaseApplication;
import com.lc.luzhengtang.MainActivity;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.base.BaseActivity;
import com.lc.luzhengtang.bean.ThridPartyBean;
import com.lc.luzhengtang.conn.ConnThird;
import com.lc.luzhengtang.util.LovelyToast;
import com.zcx.helper.http.AsyCallBack;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/17.
 */
public class LoginNextActivity extends BaseActivity {

    @BindView(R.id.img_phone)
    ImageView imgPhone;
    @BindView(R.id.edit_phone)
    EditText editPhone;
    @BindView(R.id.img_pwd)
    ImageView imgPwd;
    @BindView(R.id.edit_newpwd)
    EditText editNewpwd;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.img_news)
    ImageView imgNews;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loginnext);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_phone, R.id.edit_phone, R.id.img_pwd, R.id.edit_newpwd, R.id.btn_login,R.id.img_news})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_phone:
                break;
            case R.id.edit_phone:
                break;
            case R.id.img_pwd:
                break;
            case R.id.edit_newpwd:
                break;
            case R.id.btn_login:

                if (TextUtils.isEmpty(editPhone.getText().toString().trim())) {
                    LovelyToast.makeText(LoginNextActivity.this, "新密码不能为空", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (TextUtils.isEmpty(editNewpwd.getText().toString())) {
                    LovelyToast.makeText(LoginNextActivity.this, "确认密码不能为空", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (!editNewpwd.getText().toString().equals(editPhone.getText().toString())) {
                    LovelyToast.makeText(LoginNextActivity.this, "两次输入的密码不一致", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else {
                    getLogin();
                }
                break;


            case R.id.img_news:
                finish();

                break;
        }
    }

    public void getLogin() {

        new ConnThird(getIntent().getStringExtra("openid"), getIntent().getStringExtra("pic_url"), getIntent().getStringExtra("mobil"), getIntent().getStringExtra("name"), editNewpwd.getText().toString(), new AsyCallBack<ThridPartyBean>() {
            @Override
            public void onStart(int type) throws Exception {
                super.onStart(type);
            }

            @Override
            public void onSuccess(String toast, int type, Object o, ThridPartyBean commenBean) throws Exception {
                super.onSuccess(toast, type, o, commenBean);
                LovelyToast.makeText(LoginNextActivity.this, commenBean.getMessage(), 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);
                BaseApplication.basePreferences.saveUid(commenBean.getMember_id());
                BaseApplication.basePreferences.saveUserName(getIntent().getStringExtra("name"));
                BaseApplication.basePreferences.saveAvatar(getIntent().getStringExtra("pic_url"));
                BaseApplication.basePreferences.saveMobile(getIntent().getStringExtra("mobil"));

                startActivity(new Intent(LoginNextActivity.this, MainActivity.class));


            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }


        ).execute(LoginNextActivity.this, false);

    }



}
